"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const http_1 = __importDefault(require("http"));
const socket_io_1 = require("socket.io");
// 创建 Express 应用
const app = (0, express_1.default)();
// 创建 HTTP 服务器
const server = http_1.default.createServer(app);
// 创建 Socket.IO 服务器
const io = new socket_io_1.Server(server);
// 设置静态文件目录（可选）
app.use(express_1.default.static('public'));
// Socket.IO 连接事件
io.on('connection', (socket) => {
    console.log('A user connected:', socket.id);
    // 监听客户端消息
    socket.on('message', (msg) => {
        console.log('Message received:', msg);
        // 广播消息给所有连接的客户端
        io.emit('message', msg);
    });
    // 断开连接事件
    socket.on('disconnect', () => {
        console.log('User disconnected:', socket.id);
    });
});
// 设置服务器端口
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
    console.log(`Server is running on http://localhost:${PORT}`);
});
